<template>
  <div class="project_card">
    <div class="project_content">
      <div class="product" v-for="(item,index) in projectData" :key="index" @click="jumpToView(item)">
        <template v-if="item.template_cover">
          <img :src="JSON.parse(item.template_cover)[0].url" alt="">
        </template>
        <div class="productName" title="">{{item.subject}}</div>
      </div>
    </div>
    <div class="noData"></div>
  </div>
</template>

<script>
import {
  getProject_list,
} from "@/api.js"
export default {
  data() {
    return {
      appName: '',
      obpmFilePath: '',
      projectData:[]
    }
  },
  created() {
    console.log('111')
    let queryData = this.$route.query
    this.openParams = {
      magicAppName:queryData.magicAppName,
      appId:queryData.appId,
      linkType:queryData.linkType,
      project_no:queryData.project_no ? queryData.project_no :'',
      project_name:queryData.project_name ? queryData.project_name : '',
    }
    this.appName = this.openParams.magicAppName
    this.obpmFilePath = obpmConfig.obpmFilePath
    this.toGetProjectCard()
  },
  methods: {
    jumpToView(item) {
      let openParams = this.openParams
      let exparams = `&project_id=${item.project_id}&project_template_id=${item.project_template_id}&treedocid=${item.project_id}`
      let params = {
        linkType: '01',
        appId: openParams.appId,
        active: true,
        actionContent:'__UhJNp9pedgdvMehlyhr',//视图id
        name: item.subject,
        id:item.template_id,
        exparams: exparams,
        treedocid: item.project_id,
        magicAppName:openParams.magicAppName,
      }
      console.log('打开addTab')
      // this.addTab(params)
      top.obpmOAction('addTab',params)
    },
    toGetProjectCard() {
      let data = {
        page_lines:10, //每页条数
        page: 1, //页数
        project_no: this.openParams.project_no, //项目编号
        project_name: this.openParams.project_name, //项目名称
      }
      getProject_list(
        this.appName,
        data,
        {
          onSucess: response => {
            if(response.data.data) {
              this.projectData = response.data.data
              if(this.projectData.length == 0) {
                document.getElementsByClassName('noData')[0].innerHTML = '暂无项目'
              }
            }
          }
        }
      ) 
    }
  },
}
</script>

<style lang="scss">
@import "@/assets/style/project_card.scss";

</style>